package com.fengwei.service;

import com.fengwei.dao.MdmsUserLogMapper;
import com.fengwei.form.MdmsUserLog;
import com.fengwei.requestdata.user.MdmsUserLogPagingListData;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname MdmsUserLogService
 * @Description 操作记录
 * @Date 2020/11/24 18:18
 * @Author ludexin
 */
@Service
public class MdmsUserLogService {
    private final static Logger logger = LoggerFactory.getLogger(MdmsUserLogService.class);

    @Autowired
    private MdmsUserLogMapper mdmsUserLogMapper;

    /**
     * @param mdmsUserLogPagingListData
     * @return java.util.Map<java.lang.String, java.lang.Object>
     * @throws
     * @author ludexin
     * @Description 分页查询操作历史记录
     * @date 2020/11/24 19:38
     */
    public Map<String, Object> pagingList(MdmsUserLogPagingListData mdmsUserLogPagingListData) {
        Map<String, Object> mapPagingList = new HashMap();
        mapPagingList.put("applyUserId", mdmsUserLogPagingListData.getApplyUserid());
        mapPagingList.put("applyUserName", mdmsUserLogPagingListData.getApplyUsername());
        mapPagingList.put("databaseId", mdmsUserLogPagingListData.getDatabaseid());
        mapPagingList.put("databaseName", mdmsUserLogPagingListData.getDatabasename());
        mapPagingList.put("hostIpport", mdmsUserLogPagingListData.getHostipport());
        mapPagingList.put("dateStart", mdmsUserLogPagingListData.getDatestart());
        mapPagingList.put("dateEnd", mdmsUserLogPagingListData.getDateend());

        PageHelper.startPage(mdmsUserLogPagingListData.getPage(), mdmsUserLogPagingListData.getLimit());
        PageHelper.orderBy("id desc");
        Page<MdmsUserLog> list = mdmsUserLogMapper.selectByPage(mapPagingList);

        Map<String, Object> mapReturn = new HashMap<>(8);
        mapReturn.put("total", list.getTotal());
        mapReturn.put("limit", mdmsUserLogPagingListData.getLimit());
        mapReturn.put("page", mdmsUserLogPagingListData.getPage());
        mapReturn.put("list", list.getResult());
        return mapReturn;
    }
}
